using System;
using System.Collections.Generic;
using PokerStar.Core.Rules;

namespace PokerStar.Core
{
    public class TexasHoldem
    {
        private IList<Card> _flop;
        private Card _turn;
        private Card _river;
        //private readonly List<Card> _cards;
        //private readonly IList<IList<Card>> _combination;
        private IRule _rule;

        public TexasHoldem()
        {
            //this._cards = new List<Card>(7);
            //this._combination = new List<IList<Card>>(10); // C(5,3)=10

            CreateRuleChain();
        }

        private void CreateRuleChain()
        {
            IRule chain = new NothingRule(null);
            chain = new OnePairRule(chain);
            chain = new TwoPairsRule(chain);
            chain = new ThreeOfKindRule(chain);
            chain = new StraightRule(chain);
            chain = new FlushRule(chain);
            chain = new FullhouseRule(chain);
            chain = new FourOfKindRule(chain);
            chain = new StraightFlushRule(chain);

            _rule = chain;
        }

        public GameResult Calculate(IList<Card> players, IList<Card> flop, Card turn, Card river)
        {
            var cards = new List<Card>(7);
            cards.AddRange(players);
            cards.AddRange(flop);
            cards.Add(turn);
            cards.Add(river);
            var cx = new RuleContext(cards);
            return _rule.Test(cx);
        }

        //public void Reset(IList<Card> flop, Card turn, Card river)
        //{
        //    if (flop == null)
        //        throw new ArgumentNullException("flop");
        //    if (turn == null)
        //        throw new ArgumentNullException("turn");
        //    if (river == null)
        //        throw new ArgumentNullException("river");
        //    if (flop.Count != 3)
        //        throw new ArgumentException("flop must have 3 cards");

        //    this._flop = flop;
        //    this._turn = turn;
        //    this._river = river;

        //    this._cards.Clear();
        //    this._combination.Clear();

        //    this._cards.AddRange(flop);
        //    this._cards.Add(turn);
        //    this._cards.Add(river);

        //    // fullfil C(5,3)
        //    MathHelper.GenerateCombinations(this._cards, 5, 3, this._combination);
        //}
    }
}